<template>
	<view>
		<u-image :showLoading="true" :src="src" width="110px" height="110px"></u-image>
		<u-card padding="16" v-for="(item,index) in dataList" :key="index">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="8" text-align="left">
							<view class="u-line-1 u-m-t-2 weikaishi3">
								<span>仓库名称：{{item.warehouseName}}{{item.positionNumber}}</span>
							</view>
						</u-col>
						<u-col span="4" text-align="left">
							<view class="u-line-1 u-m-t-2 weikaishi">
								<span>状态：{{item.stockstate}}</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-2 weikaishi">
								<span>商品：{{item.goodsName}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="right">
							<view class="u-line-1 u-m-t-2 weikaishi">
								<span>商品规格：{{item.grades}}-{{item.caseWeightOne}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-row>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4 jinxingzhong">
								<span>箱皮：</span><span>{{item.caseWeight}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4 jinxingzhong">
								<span>毛重：</span><span>{{item.gweight}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4 jinxingzhong">
								<span>净重：</span><span>{{item.weight}}</span>
							</view>
						</u-col>
						<u-col span="6" text-align="left">
							<view class="u-line-1 u-m-t-4 jinxingzhong">
								<span>数量：</span><span>{{item.nums}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="left">
							<view class="u-line-1 u-m-t-4 jinxingzhong">
								<span>生产日期：</span><span>{{item.producetime}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="foot-butten" slot="foot" v-if="item.warehouseName != '废果仓'">
				<view :class="flex">
					<u-col span="12" text-align="center" @click="empty(item.id)">
						<view  class="u-m-10">
							损耗
						</view>
					</u-col>
				</view>
			</view>
			<view class="foot-butten" slot="foot" v-else>
				<view :class="flex">
					<u-col span="6" text-align="center" @click="empty(item.id)">
						<view  class="u-m-10 u-border-right">
							损耗
						</view>
					</u-col>
					<u-col span="6" text-align="center" @click="scrap(item.id)">
						<view  class="u-m-10 yizuofei">
							报废
						</view>
					</u-col>
				</view>
			</view>
		</u-card>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				flex:'',
				src:'https://s1.ax1x.com/2022/06/28/jZUc5D.png',
				dataList: [],
			}
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		onLoad(open) {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif
			this.refresh()
		},
		methods: {
			empty(id) {
				uni.showModal({
					content: '确定损耗吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '正在提交'
							})
							this.$http.post('/rest/fruits/empty',{
							},{
								params: {id:id},
								header: {
									'Authorization' :uni.getStorageSync('token'),
								}
							}).then(res => {
								uni.hideLoading()
								if(res.data.code == 200) {
									this.$refs.uToast.show({
										title: '操作成功',
										type: 'success'
									})
									this.refresh()
								} else {
									this.$refs.uToast.show({
										title: res.data.message,
										type: 'error'
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			scrap(id) {
				uni.showModal({
					content: '确定报废吗？',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '正在提交'
							})
							this.$http.post('/rest/fruits/scrap',{
							},{
								params: {id:id},
								header: {
									'Authorization' :uni.getStorageSync('token'),
								}
							}).then(res => {
								uni.hideLoading()
								if(res.data.code == 200) {
									this.$refs.uToast.show({
										title: '操作成功',
										type: 'success'
									})
									this.refresh()
								} else {
									this.$refs.uToast.show({
										title: res.data.message,
										type: 'error'
									})
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			refresh(){
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/fruits/findStorageStockListBySpec',{
				},{
					params: {},
					header: {
						'Authorization' :uni.getStorageSync('token'),
					}
				}).then(res => {
					this.dataList = res.data.data
					uni.hideLoading()
				})
			},
		}
	}
</script>

<style lang="scss">
	page{
			background-color: #ffffff;
	}
	
	.wrap {
		padding: 30rpx;
	}
	.weikaishi2{
		font-size: 36rpx;
	}
	.weikaishi3{
		font-size: 32rpx;
	}
	.huanhang{
		word-break:break-all;
	}
</style>
